package cn.sh.library.mgts.controller;

import cn.sh.library.mgts.common.Constant;
import cn.sh.library.mgts.utils.IPUtils;
import com.github.pagehelper.util.StringUtil;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName : UserInfoController
 * @Description : 用户Controller
 * @Author : chenss
 * @Date: 2020-03-10 15:28
 */
@Api(tags = "基础数据-相关API")
@RestController
@RequestMapping("/api/ipinfo/")
public class IPController {
    /**
     * 获取IP信息
     * @return
     */
    @GetMapping("/ip")
    public  Map<String, Object> ipinfo(String strongCheck) {
        Boolean checkFlag = StringUtil.isEmpty(strongCheck) ? true : false;//默认强校验验
        Map<String,Object> _result = new HashMap<>();
        try {
            _result.put("client_ip", IPUtils.getIpAddr());
            _result.put("server_port", String.valueOf(IPUtils.getRequest().getLocalPort()));
            _result.put("server_host", IPUtils.getRequest().getLocalAddr());
            _result.put("isPrivateIp", IPUtils.isPrivateIP(checkFlag));
            _result.put("strongCheck", checkFlag);
        } catch (Exception e) {
            _result.put(Constant.ERROR_MESSAGE, e.getLocalizedMessage());
        }
        return _result;
    }

}